package com.duan.laugh.sms.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.duan.laugh.common.core.util.Query;
import com.duan.laugh.common.core.util.R;
import com.duan.laugh.sms.api.entity.SmsSend;
import com.duan.laugh.sms.service.ISmsSendService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 短信发送 controller
 * </p>
 *
 * @author liutf
 * @since 2019-11-07
 */
@Api(tags = "短信发送")
@RestController
@RequestMapping("/sms-send")
public class SmsSendController {
    @Autowired
    private ISmsSendService smsSendService;

    /**
     * 新增短信发送
     *
     * @param smsSend 实体
     * @return true/false
     */
    @PostMapping
    @ApiOperation("新增短信发送")
    public R save(@RequestBody SmsSend smsSend) {
        return R.ok(smsSendService.save(smsSend));
    }

    /**
     * 根据id查看短信发送
     *
     * @param id
     * @return SmsSend
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查看短信发送")
    public R<SmsSend> getById(@PathVariable String id) {
        return R.ok(smsSendService.getById(id));
    }

    /**
     * 分页查询短信发送
     *
     * @param params 分页对象
     * @return 分页对象
     */
    @PostMapping("/page")
    @ApiOperation("分页查询短信发送")
    public IPage<SmsSend> page(@RequestBody Map<String, Object> params) {
        return smsSendService.page(new Query<>(params));
    }

    /**
     * 根据id删除短信发送
     *
     * @param id
     * @return true/false
     */
    @DeleteMapping("/{id}")
    @ApiOperation("根据id删除短信发送")
    public R removeById(@PathVariable String id) {
        return R.ok(smsSendService.removeById(id));
    }

    /**
     * 根据id修改短信发送
     *
     * @param smsSend 实体
     * @return true/false
     */
    @PutMapping
    @ApiOperation("根据id修改短信发送")
    public R updateById(@RequestBody SmsSend smsSend) {
        return R.ok(smsSendService.updateById(smsSend));
    }

}

